<?php
/**
 * Created by PhpStorm.
 * User: sunku
 * Date: 2017/12/27
 * Time: 16:46
 */

namespace Admin\Logic;
use Think\Model;

class PhaseLogLogic extends Model
{
    protected $trueTableName = 'wz_phase_log';

    /**
     * @param $params
     * @return mixed
     */
    public function searchPhaseLogList($params){
        $result = D('Resource/PhaseLog','Service')->searchPhaseLogList($params);
        if(is_array($result['dataList']) && count($result['dataList'])){
            foreach ($result['dataList'] as $k=>$phaseLog){
                //客户
                $customer = D('Resource/Customer','Service')->getCustomerInfo(['id'=>$phaseLog['customer_id']]);
                $result['dataList'][$k]['customer_name'] = $customer['company_name'];
                //查询部门信息
                $userInfo = D('Resource/User', 'Service')->getUserInfo(['id'=>$phaseLog['admin_id']]);
                $result['dataList'][$k]['admin_name'] = $userInfo['username'];
                //查询部门信息
                $departmentInfo = D('Resource/User', 'Service')->getDepartmentInfo(['id'=>$phaseLog['department_id']]);
                $result['dataList'][$k]['department_name'] = $departmentInfo['name'];
            }
        }
        return $result;
    }

    /**
     * @param $params
     * @return string
     */
    public function ajaxSavePhaseLog($params){
        $customer_id = intval($params['customer_id']);
        $customerInfo = D('Resource/Customer','Service')->getCustomerInfo(['id'=>$customer_id]);
        if(!$customerInfo){
            return Response(2003,"未查询到该客户信息");
        }
        if($customerInfo['status']!=1){
            return Response(2005,"该客户暂不可进行操作");
        }

        $result = D('Resource/PhaseLog','Service')->addPhaseLog($params);

        if(!$result){
            return Response(2004,"请求失败");
        }
        return Response(999,"请求成功");
    }
}